/**
  * The music to be played in an arena.
  *
  * @author "Brian MacCarthy";
  * @created "2007-03-04 Brian MacCarthy";
  * @revised "$Date: 2007-03-06 19:11:00 $"; 
  */

package exfist;

import java.io.File;
import java.io.IOException;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;

public class Music 
{
	private Sequence sequence;
	private Sequencer sequencer;
	private String music_location;
	/**
	 * default constructor
	 *
	 */
	public Music()
	{
		music_location="Audio/explodingfist.mid";
	}
	/**
	 * plays the music at music_location
	 *
	 */
	protected void playMusic()
	{
		try {
        // From file
		sequence = MidiSystem.getSequence(new File(music_location));
    
        // Create a sequencer for the sequence
		sequencer = MidiSystem.getSequencer();
        sequencer.open();
        sequencer.setSequence(sequence);
        // Start playing
        sequencer.setLoopCount(2);
        sequencer.start();
		} catch (IOException e) {
		} catch (MidiUnavailableException e) {
		} catch (InvalidMidiDataException e) {
		}
	}
	/**
	 * stops the music
	 *
	 */
	protected void stopMusic()
	{
		sequencer.stop();
	}
	/**
	 * sets the music to be something else
	 * @param loc the location of the new music
	 */
	protected void setMusic(String loc)
	{
		music_location = loc;
	}
}
